package com.tjtt.gwm.dao.impl;


import com.tjtt.gwm.bean.EquipmentOutIndex;
import com.tjtt.tdm.flow.bean.FlowTask;
import com.tjtt.gwm.bean.Formrelateequ;
import com.tjtt.gwm.bean.Outstoreform;
import com.tjtt.gwm.dao.EquipmentOutDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.flow.bean.FlowTaskInfo;
import com.tjtt.tdm.system.bean.Organization;

import  java.math.BigDecimal;
import java.util.List;
public class EquipmentOutDaoImpl extends BaseHibernateDao implements EquipmentOutDao {
	

	public void saveToForm(Object object){
			this.getHibernateTemplate().save(object);
		
	}
	
	public  Outstoreform  queryOutstoreFormById(String id){
		BigDecimal bd=new BigDecimal(id);
		Outstoreform fm = (Outstoreform)this.getHibernateTemplate().get(Outstoreform.class, bd);
		return fm;
	}
	
	public List<EquipmentOutIndex> queryEquoutIndxByDate(String nowdate){
		return this.getHibernateTemplate().findByNamedParam("from EquipmentOutIndex equ where equ.eoYear=:dateYear","dateYear",nowdate);	
	}

	public void updateEquipmentOutIndex(EquipmentOutIndex equipmentOutIndex){
		try{
		this.getHibernateTemplate().update(equipmentOutIndex);}
		catch(Exception e){
				e.printStackTrace();		
		}
	}
	public void saveToEquoutIndx(EquipmentOutIndex eoi){
		try{
			this.getHibernateTemplate().save(eoi);
		}
		catch(Exception e){
				e.printStackTrace();		
		}
	}
		
	public void UpdateOutstoreForm(Outstoreform osf){
		try{
		this.getHibernateTemplate().update(osf);
		}
		catch(Exception e){
				e.printStackTrace();		
		}
	}
	public List<Formrelateequ> queryFormRelateequbyId(String mainid,String equid){
		BigDecimal mainidBD= new BigDecimal(mainid);
		BigDecimal equidBD= new BigDecimal(equid);
		String []cond ={"formid","equid"};
		BigDecimal [] value ={mainidBD,equidBD};
		try{
		return this.getHibernateTemplate().findByNamedParam("from Formrelateequ equ where equ.formid=:formid and equ.equid =:equid",cond,value);
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public List <FlowTask> getFlowtaskById(String string){
		//BigDecimal bd=new BigDecimal(string);
		Long lid = Long.parseLong(string);
//		try{
//		return this.getHibernateTemplate().get(FlowTask.class, lid);
//		}
//		catch(Exception e){
//			e.printStackTrace();
//			return null;
//	    } // 主键查询
		
		
		Object[] args = {lid};
		try{
			return this.getHibernateTemplate().find("from FlowTask ft where ft.mainId=?",args);
			}
			catch(Exception e){
				e.printStackTrace();
				return null;
			}
		
	}
	

	@Override
	public void updateFormRelateequ(Formrelateequ formrelateequ) {
		try{
			this.getHibernateTemplate().update(formrelateequ);
			}
			catch(Exception e){
					e.printStackTrace();		
			}
		// TODO Auto-generated method stub	
	}
	
	public List<FlowTaskInfo> getFlowTaskInfoById(Long id){
		Object[] args = {id};
		try{
			return this.getHibernateTemplate().find("from FlowTaskInfo fti where fti.flowtaskid=?",args);
			}
			catch(Exception e){
				e.printStackTrace();
				return null;
			}
	//	return this.getHibernateTemplate().get(FlowTaskInfo.class, id);
	}
	public void updateFlowTaskInfo(FlowTaskInfo fti){
		try{
			this.getHibernateTemplate().update(fti);
			}
			catch(Exception e){
					e.printStackTrace();		
			}
	}
}
